//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "CumulativeStudentDistribution.h"
using namespace Cephei::QL::Math::Distributions;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::CCumulativeStudentDistribution (Int32 n) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phCumulativeStudentDistribution = NULL;
#endif
        QuantLib::Integer _n = (QuantLib::Integer)ValueHelper::Convert (n); //d
        _ppCumulativeStudentDistribution = new boost::shared_ptr<QuantLib::CumulativeStudentDistribution> (new QuantLib::CumulativeStudentDistribution ( _n ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::CCumulativeStudentDistribution (boost::shared_ptr<QuantLib::CumulativeStudentDistribution>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCumulativeStudentDistribution = NULL;
#endif
	_ppCumulativeStudentDistribution = &childNative;
    
}
Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::CCumulativeStudentDistribution (QuantLib::CumulativeStudentDistribution& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phCumulativeStudentDistribution = NULL;
#endif
	_ppCumulativeStudentDistribution = new boost::shared_ptr<QuantLib::CumulativeStudentDistribution> (&childNative);
    
    _CumulativeStudentDistributionOwner = owner;
    
}

Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::CCumulativeStudentDistribution (CCumulativeStudentDistribution^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCumulativeStudentDistribution = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppCumulativeStudentDistribution = new boost::shared_ptr<QuantLib::CumulativeStudentDistribution> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::CCumulativeStudentDistribution (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCumulativeStudentDistribution = NULL;
#endif
	if (!t->IsSubclassOf(CCumulativeStudentDistribution::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::CCumulativeStudentDistribution (QuantLib::Handle<QuantLib::CumulativeStudentDistribution>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phCumulativeStudentDistribution = &childNative;
	_ppCumulativeStudentDistribution = &static_cast<boost::shared_ptr<QuantLib::CumulativeStudentDistribution>>(childNative.currentLink());
    
    _CumulativeStudentDistributionOwner = owner;
}
Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::CCumulativeStudentDistribution (QuantLib::Handle<QuantLib::CumulativeStudentDistribution> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phCumulativeStudentDistribution = &childNative;
	_ppCumulativeStudentDistribution = &static_cast<boost::shared_ptr<QuantLib::CumulativeStudentDistribution>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::CCumulativeStudentDistribution (QuantLib::CumulativeStudentDistribution childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCumulativeStudentDistribution = NULL;
#endif
	_ppCumulativeStudentDistribution = new boost::shared_ptr<QuantLib::CumulativeStudentDistribution> (new QuantLib::CumulativeStudentDistribution (childNative));
    
}
#endif

Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::~CCumulativeStudentDistribution ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppCumulativeStudentDistribution != NULL)
    {
	    delete _ppCumulativeStudentDistribution;
        _ppCumulativeStudentDistribution = NULL;
    }
}
Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::!CCumulativeStudentDistribution ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppCumulativeStudentDistribution != NULL)
    {
	    delete _ppCumulativeStudentDistribution;
    }
}
QuantLib::CumulativeStudentDistribution& Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::GetReference ()
{
    if (_ppCumulativeStudentDistribution == NULL) throw REFNEW NativeNullException ();
	return **_ppCumulativeStudentDistribution;
}
boost::shared_ptr<QuantLib::CumulativeStudentDistribution>& Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::GetShared ()
{
    if (_ppCumulativeStudentDistribution == NULL) throw REFNEW NativeNullException ();
	return *_ppCumulativeStudentDistribution;
}
QuantLib::CumulativeStudentDistribution* Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::GetPointer ()
{
    if (_ppCumulativeStudentDistribution == NULL) throw REFNEW NativeNullException ();
	return &**_ppCumulativeStudentDistribution;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::CumulativeStudentDistribution>& Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::GetHandle ()
{
	if (_phCumulativeStudentDistribution == NULL)
	{
		_phCumulativeStudentDistribution = new Handle<QuantLib::CumulativeStudentDistribution> (*_ppCumulativeStudentDistribution);
	}
	return *_phCumulativeStudentDistribution;
}
#endif
bool Cephei::QL::Math::Distributions::CCumulativeStudentDistribution::HasNative () 
{
	return (_ppCumulativeStudentDistribution != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Distributions::ICumulativeStudentDistribution^ Cephei::QL::Math::Distributions::CCumulativeStudentDistribution_Factory::Create (Int32 n)
{
    return REFNEW CCumulativeStudentDistribution ( n);
}
